const token = localStorage.getItem('token')
if(!token){
    location.href = '../login/index.html'
}

function getNickName() {
    const nickname = document.querySelector(".nick-name")
    axios({
        url : '/v1_0/user/profile',
    }).then(({data:{data:res}})=>{
        nickname.innerHTML = res.name
    })
}

async function getChanList(){
    const {data:{data:{channels:res}}} = await axios({
        url : '/v1_0/channels'
    })
    const channel = document.querySelector('#channel_id')
    channel.innerHTML += res.map(item=>`<option value="${item.id}">${item.name}</option>`).join('')
}

document.querySelector('.quit').addEventListener("click",()=>{
    localStorage.removeItem('token')
    location.href = '../login/index.html'
})